(function($, gmwk) {

    // This class may not change the URL fragment directly!
  
    function QOTD(Options) {
    
        //console.info("Options", Options);
    
        var self = this;
        var sClassName = Options.sClassName;
        var jqContainer = Options.jqObjectContainer;
        var jqList = jqContainer.find(".QOTD_list");
        var fListTemplate;
        
        jqContainer.click(fClick);
        //console.info("here");
        fList();
        
        //console.info("---------> QOTD constructed");
        
        this.getClassName = function() {
            return sClassName;
        }
        
        function fClick(e) {
            var jqTarget = $(e.target);
            if (gmwk.closestObjectContainer(jqTarget) != jqContainer.attr("id")) {
                return;
            }
            console.info("fClick");
        }
        
        function fList() {
            gmwk.API.request(
                "Quote/list",
                {},
                function(Data) {
                    fRenderList(Data);
                }
            );
        }
        
        function fRenderList(Data) {
            //console.info("---------> fRenderList", Data);
            var Directive = {
                "div.QOTD_item": {
                    "Quote<-aQuotes": {
                        "span.QOTD_sQuote": "Quote.sQuote",
                        "span.QOTD_sAuthor": "Quote.sAuthor"
                  }
              }
          }
          // Compile the template to make it re-useable
          if (typeof fListTemplate == "undefined") {
              fListTemplate = jqList.find(".QOTD_list_template")
                  .compile(Directive);
          }
          // Render
          jqList.find(".QOTD_list_template")
              .render(Data, fListTemplate);
          jqList.show();
        }
      
    }
  
    gmwk.classes.QOTD = QOTD;

})(jQuery, window.gmwk);
